package com.jeeplus.modules.statistics.model.enumeration;

import com.jeeplus.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 统计查询参数枚举
 *
 * @author hanKongBin
 * @version 1.0
 * @date 2021/3/6 15:53
 */
@Getter
@AllArgsConstructor
public enum QueryParamsEnum {
    CURRENT_LAST_YEAR("5", "跨年"),
    CURRENT_YEAR("4", "本年"),
    CURRENT_MONTH("3", "本月"),
    CURRENT_WEEK("2", "本周"),
    CURRENT_DAY("1", "当天");

    /**
     * 键
     */
    private final String code;

    /**
     * 说明
     */
    private final String value;

    /**
     * 通过code取枚举
     *
     * @param code
     * @return
     */
    public static QueryParamsEnum getTypeByCode(String code) {
        return Arrays.stream(QueryParamsEnum.values()).filter(e -> StringUtils.equals(e.getCode(), code)).findAny().orElse(null);
    }
}
